Fix: show the date a picker is set to - #858
Open
DTW-Thalion wants to merge 2 commits into
Open
Conversation
NSDatePickerCell gave its formatter no format, so the cell had nothing to draw from and fell back to the description of the date object. The picker showed a full date and time whatever its datePickerElements were, in the local time zone rather than the one it was set to, and in a form no locale writes. Build the format from the elements. Each element contributes a letter to a template, and the pattern generator returns the pattern that locale writes those elements in; a build without ICU has no generator and gets a fixed order instead. The format is rebuilt whenever the elements or the locale change. NSCell keeps the text its formatter made at the time the value was set, and -[NSDateFormatter stringForObjectValue:] builds that text from a %-style format rather than from the pattern, so take -stringValue from -stringFromDate: instead. A cell decoded without a formatter gets one, as a cell built in code does.
This was referenced Jul 29, 2026
START_SET creates an autorelease pool and END_SET releases it, so the pool these tests create around the set is redundant.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
NSDatePickerCell set no format on its formatter, so the cell had nothing to draw from and fell back to the description of the date object. A picker showed a full date and time whatever its datePickerElements held, in the local time zone rather than the one it had been set to, in a form no locale writes.
The format is now built from the elements. Each element adds a letter to a template and the pattern generator returns the pattern that locale writes those elements in, and the format is rebuilt when the elements or the locale change. NSCell keeps the text its formatter made at the time the value was set, and -[NSDateFormatter stringForObjectValue:] builds that text from a %-style format rather than from the pattern, so -stringValue now comes from -stringFromDate:. A cell decoded without a formatter gets one.
A build without ICU has no pattern generator and gets a fixed field order instead. Editing a picker by keyboard or by clicking a calendar is not part of this.
Tests/gui/NSDatePicker/display.m has 7 assertions that fail before the change and pass after. Tests/gui/NSDatePicker and Tests/gui/NSDatePickerCell run 48 assertions green.
Refers to #95